package com.bl.weilan.api.controller.information;

import com.bl.weilan.service.biz.information.InformationService;
import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.InformationEntity;
import com.bl.weilan.service.biz.information.InformationService;
import com.bl.weilan.service.vo.information.InformationAddVo;
import com.bl.weilan.service.vo.information.InformationListVo;
import com.bl.weilan.service.vo.information.InformationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


/**
 * Created by liangweikang on 18/12/26.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/information"})
@Api(value = "信息相关api", description = "信息相关api")
public class InformationController extends BaseController{
    @Autowired
    InformationService informationService;


    @ApiOperation(value = "查询通知列表", notes = "查询通知列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_info_list"})
    public ApiResponseBody<InformationListVo> informationList(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,

            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        InformationListVo informationListVo = informationService.getInformationList(pageable);

        return ApiResponseBody.createSuccessBody(informationListVo);
    }

    @ApiOperation(value = "查询单条通知详情", notes = "查询单条通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_info_byid"})
    public ApiResponseBody<InformationEntity> informationDetail(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        InformationEntity informationEntity = informationService.getInformationById(id);

        return ApiResponseBody.createSuccessBody(informationEntity);
    }
}
